package cn.kooki.app.duobao.ui.Activity.Goods;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;

import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.base.BaseActivity;
import cn.kooki.app.duobao.ui.Adapter.KindMenuAdapter;

public class KindActivity extends BaseActivity implements View.OnClickListener {


    @Bind(R.id.list_view)
    ListView listView;

    @Bind(R.id.top_back)
    ImageButton topBack;
    @Bind(R.id.top_text_center)
    TextView topTextCenter;
    @Bind(R.id.top_cart)
    ImageButton topCart;
    @Bind(R.id.action_edit)
    TextView actionEdit;
    @Bind(R.id.toolbar)
    RelativeLayout toolbar;
    private View allkind;
    private View menu_search;
    private String[] kindstitle;

    @Override
    protected void setToolbar() {
        topBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        topBack.setVisibility(View.VISIBLE);
        topTextCenter.setText(R.string.kind_browse);
        topTextCenter.setVisibility(View.VISIBLE);
    }

    @Override
    protected void setLayoutContentView() {
        setContentView(R.layout.fragment_kind);
        ButterKnife.bind(this);
    }

    @Override
    protected void afterView() {
        kindstitle = getResources().getStringArray(R.array.kind_array);

        View headerview = LayoutInflater.from(this).inflate(R.layout.layout_price_kind_header, null);
        allkind = headerview.findViewById(R.id.menu_kind_all);
        menu_search = headerview.findViewById(R.id.menu_search);
        menu_search.setOnClickListener(this);
        KindMenuAdapter adapter = new KindMenuAdapter(this);
        listView.addHeaderView(headerview);
        listView.setAdapter(adapter);
        allkind.setOnClickListener(this);
        final int[] intArray = getResources().getIntArray(R.array.kind_ids);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                HashMap<String, String> params = new HashMap<>();
                params.put("title", kindstitle[position - 1]);
                params.put("type", intArray[position - 1] + "");
                intent(SearchResultActivity.class, params);
            }
        });
    }


    @Override
    public void onClick(View v) {
        if (v == menu_search) {

            intent(SearchActivity.class);
        }
        if (v == allkind) {
            HashMap<String, String> params = new HashMap<>();
            params.put("title", "全部商品");
            intent(SearchResultActivity.class, params);
        }

    }
}
